import QtQuick 2.0
import QtQuick.Controls 2.7

Rectangle {
    id: dateSlecteRec
    property alias text:  dateText.text
    property string  def: ""
    border.width: 1
    border.color: "green";
    Button {
        id: dateSelectBtn
        width: 100
        height: 30
        anchors.verticalCenter: parent.verticalCenter
        anchors.leftMargin: 1
        anchors.left: parent.left
        onClicked: {
            ccalendarPopup.open();
        }

        contentItem: Text {
            id: dateText
            text: dateSlecteRec.def
            color: "grey"
            verticalAlignment: Text.AlignVCenter


        }
        background: Rectangle {
            color: "white"
        }

        Connections {
            target: ccalendarPopup.ccbtn
            onClicked: {
                dateText.text = ccalendarPopup.calendar.get_selected_day();
                dateText.color = "green"
            }
        }

    }
    Button {
        anchors.right: parent.right
        anchors.rightMargin: 1
        anchors.verticalCenter: parent.verticalCenter
        anchors.left: dateSelectBtn.right
        height: 30
        background: Rectangle {
            Image {
                anchors.right: parent.right
                width: 30
                height: 30
                source: "qrc:/images/clear.png"
            }
        }

        onClicked: {
            dateText.text = parent.def
            dateText.color = "grey"
        }
    }
    Popup {
        id: ccalendarPopup
        parent: Overlay.overlay
        width: parent.width
        height: 300
        property alias calendar : ccalendar
        x: 0
        y: parent.height - height

        padding: 0
        margins: 0
        Rectangle {
            id: popControl;
            width: parent.width;
            height: 64
            color:"#383838"
            Button {
                anchors.margins: 10
                anchors.left: parent.left
                anchors.top: parent.top
                background: Rectangle{
                    opacity: 0
                }
                contentItem: Text {
                    text: qsTr("取消")
                    color: "white"
                    font.pixelSize: 20
                }

                onClicked: {
                    ccalendarPopup.close()
                }
            }
            Button {
                id: ccalendarbtn
                anchors.right: parent.right
                anchors.margins: 10
                anchors.top: parent.top
                background: Rectangle{
                    opacity: 0
                }
                contentItem: Text {
                    text: qsTr("确认")
                    color: "white"
                    font.pixelSize: 20
                }
                onClicked: {
                    ccalendarPopup.close()
                }

            }
        }
        CCalendar {
            id: ccalendar
            anchors.top: popControl.bottom
            anchors.horizontalCenter: parent.Center
            height: parent.height-popControl.height
            width: parent.width;
            Component.onCompleted: {

            }
        }
        property alias ccbtn: ccalendarbtn
    }

}
